home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MISC / SHELL.ARC / Shell / Sources / c / DBarGraph < prev    next >
Encoding:
Text File  |  1994-06-25  |  1.7 KB  |  94 lines

  1. #include <stdio.h>
  2.  
  3. #include "DeskLib:WimpSWIs.h"
  4.  
  5. #include "Shell.Extra.h"
  6. #include "Shell.BarGraph.h"
  7. #include "Shell.SafeAlloc.h"
  8.  
  9.  
  10.  
  11. typedef struct    {
  12.     int    spacing;
  13.     int    barwidth;
  14.     double    *data;
  15.     int    numbars;
  16.     int    forecol, backcol;
  17.     double    scale, zero;
  18.     }
  19.     Shell_dbarinfo;
  20.  
  21.  
  22. static void Shell_DoubleBarRedrawer(
  23.     Shell_convertpoint    convert,
  24.     wimp_point        rectsize,
  25.     void            *reference,
  26.     const wimp_rect        *redrawrect
  27.  
  28.     )
  29.  
  30. {    Shell_dbarinfo    *barinfo = (Shell_dbarinfo *) reference;
  31.     int        imin, imax, i;
  32.  
  33. imin = redrawrect->min.x / barinfo->spacing;
  34. imax = redrawrect->max.x / barinfo->spacing + 1;
  35.  
  36. Shell_MakeGE( imin, 0);
  37. Shell_MakeLE( imax, barinfo->numbars);
  38.  
  39. for ( i=imin; i<imax; i++)    {
  40.     int y = (int) ( (barinfo->data[i] + barinfo->zero) * barinfo->scale);
  41.     int x = i*barinfo->spacing;
  42.  
  43.     Wimp_SetColour( barinfo->forecol);
  44.     Shell_RectangleFill2(
  45.         x, 0,
  46.         x + barinfo->barwidth, y,
  47.         convert);
  48.  
  49.     if ( y!=rectsize.y)    {
  50.         Wimp_SetColour( barinfo->backcol);
  51.         Shell_RectangleFill2(
  52.             x, y,
  53.             x + barinfo->barwidth, rectsize.y,
  54.             convert
  55.             );
  56.         }
  57.     }
  58.  
  59. return;
  60. }
  61.  
  62.  
  63.  
  64.  
  65. Shell_rectblock *Shell_AddDoubleBarGraph(
  66.     Shell_windblock *wind,
  67.     int x, int y,
  68.     int numbars, int spacing, int barwidth, int maxheight,
  69.     double *data,
  70.     double    scale,
  71.     double    zero,
  72.     int forecol, int backcol
  73.     )
  74. {
  75. Shell_dbarinfo    *barinfo = (Shell_dbarinfo *) Shell_SafeMalloc( sizeof( Shell_dbarinfo));
  76. Shell_rectblock    *rect;
  77.  
  78. barinfo->spacing    = spacing;
  79. barinfo->barwidth    = barwidth;
  80. barinfo->data        = data;
  81. barinfo->numbars    = numbars;
  82. barinfo->scale        = scale;
  83. barinfo->zero        = zero;
  84. barinfo->forecol    = forecol;
  85. barinfo->backcol    = backcol;
  86.  
  87. rect = Shell_AddRectangle3( wind, x, y, spacing*numbars, maxheight, Shell_DoubleBarRedrawer, barinfo);
  88. Shell_MakeRectIcon( rect, forecol, backcol, "r2");
  89. return rect;
  90. }
  91.  
  92.  
  93.  
  94.